/*
 * Copyright (c) 2010, VeRSI Consortium
 *   (Victorian eResearch Strategic Initiative, Australia)
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the VeRSI, the VeRSI Consortium members, nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package versi.vitro.oaiserviceprovider.application;

import static versi.vitro.oaiserviceprovider.helper.PropertyFileReader.*;
import versi.vitro.oaiserviceprovider.helper.Key;

/**
 * OAI service environment constants.
 */
public class Environment {

    /** VITRO Protocol. Either HTTP or HTTPS. */
    public static final String VITRO_PROTOCOL = loadProperty(Key.VITRO_PROTOCOL);

    /** VITRO host name. */
    public static final String VITRO_HOST = loadProperty(Key.VITRO_HOST);

    /** VITRO host port. Usually (port 8080 or port 8443) */
    public static final String VITRO_PORT = loadProperty(Key.VITRO_PORT);

    /** VITRO webapp name in Tomcat container. Usually (vivo or vitro) */
    public static final String VITRO_WEBAPP_NAME = loadProperty(Key.VITRO_WEBAPP_NAME);

    /** VITRO Jena Database name. */
    public static final String VITRO_JENA_DATABASE = loadProperty(Key.VITRO_JENA_DATABASE);

    /** Username for login to VITRO Jena Database. */
    public static final String VITRO_JENA_USERNAME = loadProperty(Key.VITRO_JENA_USERNAME);

    /** Password for login to VITRO Jena Database. */
    public static final String VITRO_JENA_PASSWORD = loadProperty(Key.VITRO_JENA_PASSWORD);

    /** Output location of OAICAT record. */
    public static final String OUTPUT_LOCATION = loadProperty(Key.OUTPUT_LOCATION);

    /** Output location of OAICAT record. */
    public static final String RESOURCE_MODELS = loadProperty(Key.RESOURCE_MODELS);
    
    /** Validate against given schemas. */
    public static final Boolean SHOULD_VALIDATE_AGAINST_SCHEMA;
    static {
	String schemasValidationStr = loadProperty(Key.SCHEMAS_VALIDATION);
	SHOULD_VALIDATE_AGAINST_SCHEMA = schemasValidationStr == null ? Boolean.FALSE : Boolean
		.valueOf(schemasValidationStr);
    };
    
    /** Validate against given schemas. */
    public static final Boolean SHOULD_USE_ADDITIONAL_INFO_MODEL;
    static {
	String useAddInfoStr = loadProperty(Key.USE_ADDITIONAL_INFO_MODEL);
	SHOULD_USE_ADDITIONAL_INFO_MODEL = useAddInfoStr == null ? Boolean.FALSE : Boolean
		.valueOf(useAddInfoStr);
    };
    
    
    

    /**
     * Load an environment property value.
     * 
     * @param key
     *            Property key.
     * @return String Property value.
     */
    protected static String loadProperty(String key) {
	return ENVIRONMENT_PROPERTY_FILE_READER.getValue(key);
    }
}
